package com.example.controller;

import com.example.entity.Result;
import com.example.entity.pojo.Dept;
import com.example.service.DeptService;
import com.example.utils.MyJwtUtils;
import com.example.utils.MyThreadLocalUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result<List<Dept>> selectAll() {
        Map<String, Object> value = MyThreadLocalUtils.getValue();
        System.out.println("从ThreadLocal中获取的令牌解析的结果是===============================" + value);
        List<Dept> depts = deptService.selectAll();
        return Result.ok(depts);
    }
    @DeleteMapping ("/{id}")
    public Result<Object> deleteById(@PathVariable Integer id) {
        int i = deptService.deleteById(id);
        return i>=1?Result.ok("ok"):Result.error("id为"+id+"的部门删除失败,请确认id后重试!");
    }



}
